<?php
class BaiDuCategorySvc extends BaiDuCommon
{
    /*
        开通自定义分类
        params
            shop_id 商户唯一id
    */
    public function openCategory($shop_id = '')
    {
        $data = array();
        $data['shop_id'] = (int)$shop_id;

        return $data;
    }

    /*
        请求开通自定义分类
        params
            data 开通自定义分类对象(openCategory)
    */
    public function sendOpenCategory($data = array())
    {
        $cmd = "sku.shop.category.open";
        $postData = $this->getPostData($cmd, $data);

        $this->DLOG("open_category : " . json_encode($postData), "run", "channel_baidu");
        
        $res = $this->_sendReq($postData);

        $this->DLOG("open_category_res : " . json_encode($res), "run", "channel_baidu");

        return $res['body'];
    }

    /*
        关闭自定义分类
        params
            shop_id 商户唯一id
    */
    public function closeCategory($shop_id = '')
    {
        $data = array();
        $data['shop_id'] = (int)$shop_id;

        return $data;
    }

    /*
        请求关闭自定义分类
        params
            data 开通自定义分类对象(closeCategory)
    */
    public function sendCloseCategory($data = array())
    {
        $cmd = "sku.shop.category.close";
        $postData = $this->getPostData($cmd, $data);

        $this->DLOG("close_category : " . json_encode($postData), "run", "channel_baidu");
        
        $res = $this->_sendReq($postData);

        $this->DLOG("close_category_res : " . json_encode($res), "run", "channel_baidu");

        return $res['body'];
    }

    /*
        新增自定义分类
        params
            shop_id 商户唯一id
            parent_category_id 父级分类id  一级分类为0
            name 分类名称 最大字符为50个字符
            rank 分类排序 最小为1 最大为100000
    */
    public function addCategory($shop_id = '', $parent_category_id = 0, $name = '', $rank = 0)
    {
        $data = array();
        $data['shop_id'] = $shop_id;
        $data['parent_category_id'] = $parent_category_id;
        $data['name'] = $name;
        $data['rank'] = $rank;

        return $data;
    }

    /*
        请求添加自定义分类
        params
            data 添加自定义分类对象(addCategory)
    */
    public function sendAddCategory($data = array())
    {
        $cmd = "sku.shop.category.create";
        $postData = $this->getPostData($cmd, $data);

        $this->DLOG("add_category : " . json_encode($postData), "run", "channel_baidu");
        
        $res = $this->_sendReq($postData);

        $this->DLOG("add_category_res : " . json_encode($res), "run", "channel_baidu");

        return $res['body'];
    }

    /*
        修改自定义分类
        params
            shop_id 商户唯一id
            category_id 分类id
            name 分类名称 最大字符为50个字符
            rank 分类排序 最小为1 最大为100000
    */
    public function updateCategory($shop_id = '', $category_id = 0, $name = '', $rank = '')
    {
        $data = array();
        $data['shop_id'] = $shop_id;
        $data['category_id'] = $category_id;
        $data['name'] = $name;
        $data['rank'] = $rank;

        return $data;
    }

    /*
        请求修改自定义分类
        params
            data 修改自定义分类对象(updateCategory)
    */
    public function sendUpdateCategory($data = array())
    {
        $cmd = "sku.shop.category.update";
        $postData = $this->getPostData($cmd, $data);

        $this->DLOG("update_category : " . json_encode($postData), "run", "channel_baidu");
        
        $res = $this->_sendReq($postData);

        $this->DLOG("update_category_res : " . json_encode($res), "run", "channel_baidu");

        return $res['body'];
    }

    /*
        获取自定义分类
        params
            shop_id 商户唯一id
    */
    public function getCategory($shop_id = '')
    {
        $data = array();
        $data['shop_id'] = $shop_id;

        return $data;
    }

    /*
        请求获取自定义分类
        params
            data 获取自定义分类对象(getCategory)
    */
    public function sendGetCategory($data = array())
    {
        $cmd = "sku.shop.category.get";
        $postData = $this->getPostData($cmd, $data);

        $this->DLOG("get_category : " . json_encode($postData), "run", "channel_baidu");
        
        $res = $this->_sendReq($postData);

        $this->DLOG("get_category_res : " . json_encode($res), "run", "channel_baidu");

        return $res['body'];
    }

    /*
        删除自定义分类
        params
            shop_id 商户唯一id
            category_id 分类id
    */
    public function delCategory($shop_id = '', $category_id = '')
    {
        $data = array();
        $data['shop_id'] = $shop_id;
        $data['category_id'] = $category_id;

        return $data;
    }

    /*
        请求删除自定义分类
        params
            data 删除自定义分类对象(delCategory)
    */
    public function sendDelCategory($data = array())
    {
        $cmd = "sku.shop.category.delete";
        $postData = $this->getPostData($cmd, $data);

        $this->DLOG("del_category : " . json_encode($postData), "run", "channel_baidu");
        
        $res = $this->_sendReq($postData);

        $this->DLOG("del_category_res : " . json_encode($res), "run", "channel_baidu");

        return $res['body'];
    }
}
?>